package mysql

import "gorm.io/gorm"

type Class struct {
	gorm.Model
	Name    string  `gorm:"type:varchar(20);comment:预约课程的名称"`
	Address string  `gorm:"type:varchar(20);comment:预约地点"`
	Types   int     `gorm:"type:int;comment:预约的类型：1-团课，2-私教"`
	Price   float32 `gorm:"type:decimal(10,2);comment:预约课程的价格"`
	Num     int     `gorm:"type:int;comment:预约人数"`
}

func (Class) TableName() string {
	return "class"
}

func (c *Class) Add() error {
	return DB.Create(&c).Error
}

func (c *Class) Detail(id int) (result []Class, err error) {
	err = DB.Where("id=?", id).Find(&result).Error
	if err != nil {
		return nil, err
	}
	return result, nil
}

func (c *Class) FindClassId(id int) (result Class, err error) {
	err = DB.Where("id=?", id).Find(&result).Error
	if err != nil {
		return Class{}, err
	}
	return result, nil
}
